package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.SmokeDrink;
import com.noahplat.person.service.SmokeDrinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: SmokeDrinkController
 * @Description: 吸烟喝酒习controller
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/smokeDrink")
@Validated
public class SmokeDrinkController {

    @Autowired
    private SmokeDrinkService smokeDrinkService;

    /**
     * 获取吸烟喝酒习惯
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:SmokeDrinkController:getSmokeDrink')")
    @GetMapping("/getSmokeDrink")
    public Result getSmokeDrink(){
        return smokeDrinkService.getSmokeDrink();
    }

    /**
     * 添加吸烟喝酒习惯
     * @param smokeDrink
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:SmokeDrinkController:addSmokeDrink')")
    @PostMapping("/addSmokeDrink")
    public Result addSmokeDrink(@RequestBody SmokeDrink smokeDrink){
        return smokeDrinkService.addSmokeDrink(smokeDrink);
    }
    /**
     * 修改吸烟喝酒习惯
     * @param smokeDrink
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:SmokeDrinkController:updateSmokeDrink')")
    @PutMapping("/updateSmokeDrink")
    public Result updateSmokeDrink(@RequestBody SmokeDrink smokeDrink){
        return smokeDrinkService.updateSmokeDrink(smokeDrink);
    }
    /**
     * 删除吸烟喝酒习惯
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:SmokeDrinkController:delSmokeDrink')")
    @DeleteMapping("/delSmokeDrink")
    public Result delSmokeDrink(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return smokeDrinkService.delSmokeDrink(id);
    }
    /**
     * 分页获取吸烟喝酒习惯
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:SmokeDrinkController:getAdminSmokeDrink')")
    @GetMapping("/getAdminSmokeDrink")
    public Result getAdminSmokeDrink(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return smokeDrinkService.getAdminSmokeDrink(page, limit);
    }
    /**
     * 获取吸烟喝酒习惯详细信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:SmokeDrinkController:getSmokeDrinkById')")
    @GetMapping("/getSmokeDrinkById")
    public Result getSmokeDrinkById(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return smokeDrinkService.getSmokeDrinkById(id);
    }
}
